<template>
    <div class="app-container">
        <div class="search-form-box" style="display: flex;">
            <el-form ref="formRef" :inline="true">
                <el-form-item label="年份">
                    <el-select v-model="yearStr" @change="yearStrChange" placeholder="请选择年份">
                        <el-option v-for="item in yearsOptions" :key="item.value" :label="item.label" :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <span>
                <el-button
                    v-if='isSchoolScholarship || schoolStatistics'
                    type="warning"
                    plain
                    icon="el-icon-download"
                    size="mini"
                    @click="handleAllExport"
                >导出</el-button>
            </span>
        </div>
        <el-row class="statisticsPie" :gutter="40">
            <template v-if='isScholarship || isSubsidy '>
                <el-col :span="12" style="height: 100%;">
                    <div class="statisticsPie-item">
                        <div class="statisticsPie-item-title">
                            {{isScholarship ? '人数': '本科'}}
                        </div>
                        <div class="statisticsPie-item-content">
                            <div class="content-echarts" id="statisticsXzLeft">

                            </div>
                            <div class="content-detail">
                                <template v-if="isScholarship">
                                    <div class="content-detail-item">总计人数：{{ Number(gjstatistics.benEduTotalPersonNum)+ Number(gjstatistics.zhuanEduTotalPersonNum) }}人</div>
                                    <div class="content-detail-item">本科总人数：{{ gjstatistics.benEduTotalPersonNum }}人</div>
                                    <div class="content-detail-item">专科总人数：{{ gjstatistics.zhuanEduTotalPersonNum }}人</div>
                                </template>
                                <template v-if="isSubsidy">
                                    <div class="content-detail-item">总计金额：{{this.subsidyStatistics.totalMoneyBen || 0}}元</div>
                                    <div class="content-detail-item" v-for="item in this.subsidyStatistics.statisNumBenList" :key="item.typeName">
                                        {{ item.typeName }}：{{item.money}}元</div>
                                </template>
                            </div>
                        </div>
                    </div>
                </el-col>
                <el-col :span="12" style="height: 100%;">
                    <div class="statisticsPie-item">
                        <div class="statisticsPie-item-title">
                            {{isScholarship ? '金额': '专科'}}
                        </div>
                        <div class="statisticsPie-item-content">
                            <div class="content-echarts" id="statisticsXzRight">

                            </div>
                            <div class="content-detail">
                                <template v-if="isScholarship">
                                    <div class="content-detail-item">总计金额：{{Number(gjstatistics.benEduTotalMoney) + Number(gjstatistics.zhuanEduTotalMoney) }}元</div>
                                    <div class="content-detail-item">本科总金额：{{ gjstatistics.benEduTotalMoney }}元</div>
                                    <div class="content-detail-item">专科总金额：{{ gjstatistics.zhuanEduTotalMoney }}元</div>
                                </template>
                                <template v-if="isSubsidy">
                                    <div class="content-detail-item">总计金额：{{this.subsidyStatistics.totalMoneyZhuan || 0}}元</div>
                                    <div class="content-detail-item" v-for="item in this.subsidyStatistics.totalStatisZhuanList" :key="item.typeName">
                                        {{ item.typeName }}：{{item.money}}元</div>
                                </template>
                            </div>
                        </div>
                    </div>
                </el-col>
            </template>
            <template v-if='isSchoolScholarship || schoolStatistics'>
                <span style="display: block;padding-left: 20px;">奖学金总览</span>
                <el-col :span="8" style="height: 100%;" id="schoolScholarshipStatistics">
                </el-col>
                <el-col :span="8" style="height: 100%;">
                    <div class="schoolScholarship-list">
                        <div class="schoolScholarship-list-header">
                            <div class="header-title">
                                本科
                            </div>
                            <div class="header-item">
                                <div class="header-item-left">
                                    总人数：{{benSchoolScholarship.personTotal}}
                                </div>
                                <div class="header-item-right">
                                    总计金额：{{benSchoolScholarship.totalMoney.toFixed(2)}}万元
                                </div>
                            </div>
                        </div>
                        <div class="schoolScholarship-list-container">
                            <div class="container-item" v-for="item in benSchoolScholarship.list" :key="item.ID">
                                <div class="container-item-left">
                                    {{item.typeName}}：{{item.personNum}}人
                                </div>
                                <div class="container-item-right">
                                    总计金额：{{item.totalMoney}}元
                                </div>
                            </div>
                        </div>
                    </div>
                </el-col>
                <el-col :span="8" style="height: 100%;">
                    <div class="schoolScholarship-list">
                        <div class="schoolScholarship-list-header">
                            <div class="header-title">
                                专科
                            </div>
                            <div class="header-item">
                                <div class="header-item-left">
                                    总人数：{{zhuanSchoolScholarship.personTotal}}
                                </div>
                                <div class="header-item-right">
                                    总计金额：{{zhuanSchoolScholarship.totalMoney.toFixed(2)}}万元
                                </div>
                            </div>
                        </div>
                        <div class="schoolScholarship-list-container">
                            <div class="container-item" v-for="item in zhuanSchoolScholarship.list" :key="item.ID">
                                <div class="container-item-left">
                                    {{item.typeName}}：{{item.personNum}}人
                                </div>
                                <div class="container-item-right">
                                    总计金额：{{item.totalMoney}}元
                                </div>
                            </div>
                        </div>
                    </div>
                </el-col>
                <!-- <el-col :span="6" style="height: 100%;">
                    <div class="schoolScholarship-list">
                        <div class="schoolScholarship-list-header">
                            <div class="header-title">
                                专升本
                            </div>
                            <div class="header-item">
                                <div class="header-item-left">
                                    总人数：{{zhuanUpBenSchoolScholarship.personTotal}}
                                </div>
                                <div class="header-item-right">
                                    总计金额：{{zhuanUpBenSchoolScholarship.totalMoney}}
                                </div>
                            </div>
                        </div>
                        <div class="schoolScholarship-list-container">
                            <div class="container-item" v-for="item in zhuanUpBenSchoolScholarship.list" :key="item.ID">
                                <div class="container-item-left">
                                    {{item.typeName}}：{{item.personNum}}人
                                </div>
                                <div class="container-item-right">
                                    总计金额：{{item.totalMoney}}元
                                </div>
                            </div>
                        </div>
                    </div>
                </el-col> -->
            </template>
        </el-row>
        <div class="statisticsBar">
            <div class="statisticsBar-title">
                {{ isScholarship ? '各院系奖学金统计' : '各院系奖学金统计' }}
            </div>
            <div class="statisticsBar-content" id="statisticsYx">

            </div>
        </div>
        <div class="statisticsTable">
            <template v-if="isSchoolScholarship">
                <div class="statisticsTable-SchoolScholarshipQuery">
                    <div class="statisticsTable-SchoolScholarshipQuery-item">
                        本科奖学金统计
                        <!-- <el-select v-model="schoolScholarshipStudentType" @change="studentTypeChange" placeholder="请选择">
                            <el-option label="全部" value="">全部</el-option>
                            <el-option label="本科" value="ben">本科</el-option>
                            <el-option label="专科" value="zhuan">专科</el-option>
                        </el-select> -->
                    </div>
                    <el-button
                        type="warning"
                        plain
                        icon="el-icon-download"
                        size="mini"
                        @click="handleExport('ben')"
                    >导出</el-button>
                </div>

                <el-table :data="tableData" id="schoolScholarshipStatisticsTableBen" style="width: 100%"  show-summary>
                    <el-table-column prop="collegeName" label="院系名称" :show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column v-for="item in scholarshipTypeList" :key="item.schoolTypeId + 'ben'" :prop="item.schoolTypeId + 'ben'" :label="item.schoolTypeName + '(人)'" :show-overflow-tooltip="true" :min-width="item.schoolTypeName.length*10 + 10">
                    </el-table-column>
                    <el-table-column prop="benTotalPersonNum" key="benTotalPersonNum" label="总人数" :show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column prop="benTotalMoney" key="benTotalMoney" label="总金额（万元）" :show-overflow-tooltip="true">
                    </el-table-column>
                </el-table>

                <div class="statisticsTable-SchoolScholarshipQuery" style="margin-top: 8px;">
                    <div class="statisticsTable-SchoolScholarshipQuery-item">
                        专科奖学金统计
                    </div>
                    <el-button
                        type="warning"
                        plain
                        icon="el-icon-download"
                        size="mini"
                        @click="handleExport('zhuan')"
                    >导出</el-button>
                </div>
                <el-table :data="tableData" id="schoolScholarshipStatisticsTableZhuan" style="width: 100%"  show-summary>
                    <el-table-column prop="collegeName" label="院系名称" :show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column 
                        v-for="item in scholarshipTypeList" 
                        :key="item.schoolTypeId + 'zhuan'" 
                        :prop="item.schoolTypeId + 'zhuan'" 
                        :label="item.schoolTypeName +'(人)'" 
                        :show-overflow-tooltip="true"
                        :min-width="item.schoolTypeName.length*10 + 10"
                        >
                    </el-table-column>
                    <el-table-column prop="zhuanTotalPersonNum" key="zhuanTotalPersonNum" label="总人数" :show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column prop="zhuanTotalMoney"  key="zhuanTotalMoney" label="总金额（万元）" :show-overflow-tooltip="true">
                    </el-table-column>
                </el-table>

                <div class="statisticsTable-SchoolScholarshipQuery" style="margin-top: 8px;">
                    <div class="statisticsTable-SchoolScholarshipQuery-item">
                        四大组织奖学金统计
                    </div>
                    <el-button
                        type="warning"
                        plain
                        icon="el-icon-download"
                        size="mini"
                        @click="handleExport('four')"
                    >导出</el-button>
                </div>
                <el-table :data="fourOrganizationTableData" id="schoolScholarshipStatisticsTableFour" style="width: 100%">
                    <el-table-column prop="remark" label="名称" :show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column prop="benPersonNum" label="本科（人）" :show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column prop="zhuanPersonNum"  label="专科（人）" :show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column prop="totalPersonNum"  label="合计（人）" :show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column prop="benMoney"  label="本科金额（万元）" :show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column prop="zhuanMoney"  label="专科金额（万元）" :show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column prop="totalMoney"  label="合计金额（万元）" :show-overflow-tooltip="true">
                    </el-table-column>
                </el-table>
            </template>
            
            <el-table v-else :data="tableData" id="schoolScholarshipStatisticsTable" style="width: 100%">
                <template v-if='isScholarship'>
                    <el-table-column prop="collageName" label="院系" :show-overflow-tooltip="true" width="120">
                    </el-table-column>
                    <el-table-column label="本科（万元）" prop="eduTotalMoney"></el-table-column>
                    <el-table-column label="专科（万元）" prop="zhuanTotalMoney"></el-table-column>
                    <el-table-column prop="collageNameeven" label="院系" :show-overflow-tooltip="true" width="120">
                    </el-table-column>
                    <el-table-column label="本科（万元）" prop="eduTotalMoneyeven"></el-table-column>
                    <el-table-column label="专科（万元）" prop="zhuanTotalMoneyeven"></el-table-column>
                </template>
                <template v-if='isSubsidy'>
                    <el-table-column prop="collageName" label="院系" :show-overflow-tooltip="true" width="120">
                    </el-table-column>
                    <el-table-column label="本科">
                        <template v-if="isScholarship">
                            <el-table-column prop="benGjPerson" label="国家奖学金" :show-overflow-tooltip="true">
                            </el-table-column>
                            <el-table-column prop="benGjlzPerson" label="国家励志奖学金" :show-overflow-tooltip="true">
                            </el-table-column>
                            <el-table-column label="合计" :show-overflow-tooltip="true">
                            <template slot-scope="scope">
                                {{ totalFun(scope.row.benGjPerson, scope.row.benGjlzPerson) }}
                            </template>
                        </el-table-column>
                        </template>
                        <template v-if="isSubsidy">
                            <el-table-column v-for="item in subsidyType" :key="item.typeName" :prop="item.typeName + '本科'" :label="item.typeName"
                                :show-overflow-tooltip="true">
                            </el-table-column>
                            <el-table-column label="合计" :prop="'本科'" :show-overflow-tooltip="true">
                            </el-table-column>
                        </template>
                    </el-table-column>
                    <el-table-column label="专科">
                        <template v-if="isScholarship">
                            <el-table-column prop="zhuanGjPerson" label="国家奖学金" :show-overflow-tooltip="true">
                            </el-table-column>
                            <el-table-column prop="zhuanGjlzPerson" label="国家励志奖学金" :show-overflow-tooltip="true">
                            </el-table-column>
                            <el-table-column label="合计" :show-overflow-tooltip="true">
                                <template slot-scope="scope">
                                    {{ totalFun(scope.row.zhuanGjPerson, scope.row.zhuanGjlzPerson) }}
                                </template>
                            </el-table-column>
                        </template>
                        <template v-if="isSubsidy">
                            <el-table-column v-for="item in subsidyType" :key="item.typeName" :prop="item.typeName + '专科'" :label="item.typeName"
                                :show-overflow-tooltip="true">
                            </el-table-column>
                            <el-table-column label="合计" :prop="'专科'" :show-overflow-tooltip="true">
                            </el-table-column>
                        </template>
                    </el-table-column>
                    <el-table-column prop="collageNameeven" label="院系" :show-overflow-tooltip="true" width="120">
                    </el-table-column>
                    <el-table-column label="本科">
                        <template v-if="isScholarship">
                            <el-table-column prop="benGjPersoneven" label="国家奖学金" :show-overflow-tooltip="true">
                            </el-table-column>
                            <el-table-column prop="benGjlzPersoneven" label="国家励志奖学金" :show-overflow-tooltip="true">
                            </el-table-column>
                            <el-table-column label="合计">
                                <template slot-scope="scope">
                                    {{ totalFun(scope.row.benGjPersoneven, scope.row.benGjlzPersoneven) }}
                                </template>
                            </el-table-column>
                        </template>
                        <template v-if="isSubsidy">
                            <el-table-column v-for="item in subsidyType" :key="item.typeName" :prop="item.typeName + '本科even'" :label="item.typeName"
                                :show-overflow-tooltip="true">
                            </el-table-column>
                            <el-table-column label="合计" :prop="'本科even'" :show-overflow-tooltip="true">
                            </el-table-column>
                        </template>
                    </el-table-column>
                    <el-table-column label="专科">
                        <template v-if="isScholarship">
                            <el-table-column prop="zhuanGjPersoneven" label="国家奖学金" :show-overflow-tooltip="true">
                            </el-table-column>
                            <el-table-column prop="zhuanGjlzPersoneven" label="国家励志奖学金" :show-overflow-tooltip="true">
                            </el-table-column>
                            <el-table-column label="合计">
                                <template slot-scope="scope">
                                    {{ totalFun(scope.row.zhuanGjPersoneven, scope.row.zhuanGjlzPersoneven) }}
                                </template>
                            </el-table-column>
                        </template>
                        <template v-if="isSubsidy">
                            <el-table-column v-for="item in subsidyType" :key="item.typeName" :prop="item.typeName + '专科even'" :label="item.typeName"
                                :show-overflow-tooltip="true">
                            </el-table-column>
                            <el-table-column label="合计" :prop="'专科even'" :show-overflow-tooltip="true">
                            </el-table-column>
                        </template>
                    </el-table-column>
                </template>
            </el-table>
        </div>
        <template v-if="isScholarship || isSubsidy">
            <div  class="statisticsBar">
                <div class="statisticsBar-title">
                    学生获奖省份及人数
                </div>
                <div class="statisticsBar-content" id="provincestatistics">

                </div>
            </div>
            <div class="statisticsTable">
                <el-table :data="provincesTableData" style="width: 100%">
                    <el-table-column prop="provinceName" label="省份" :show-overflow-tooltip="true" width="120">
                    </el-table-column>
                    
                    <template v-if="isSubsidy">
                        <el-table-column label="本科" prop="personNum">
                            <el-table-column v-for="item in subsidyType" :key="item.typeName" :prop="'本科-'+item.typeName" :label="item.typeName"
                                    :show-overflow-tooltip="true">
                            </el-table-column>
                        </el-table-column>
                        <el-table-column label="专科" prop="zhuanPersonNum">
                            <el-table-column v-for="item in subsidyType" :key="item.typeName" :prop="'专科-'+item.typeName" :label="item.typeName"
                                    :show-overflow-tooltip="true">
                            </el-table-column>
                        </el-table-column>
                    </template>
                    <template v-else>
                        <el-table-column label="本科" prop="personNum"></el-table-column>
                        <el-table-column label="专科" prop="zhuanPersonNum"></el-table-column>
                    </template>
                    
                    <el-table-column prop="provinceNameEven" label="省份" :show-overflow-tooltip="true" width="120">
                    </el-table-column>
                    <template v-if="isSubsidy">
                        <el-table-column label="本科" prop="personNumEven">
                            <el-table-column v-for="item in subsidyType" :key="item.typeName" :prop="'本科-' + item.typeName + 'Even'" :label="item.typeName"
                                :show-overflow-tooltip="true">
                            </el-table-column>
                        </el-table-column>
                        <el-table-column label="专科" prop="zhuanPersonNumEven">
                            <el-table-column v-for="item in subsidyType" :key="item.typeName" :prop="'专科-' +item.typeName + 'Even'" :label="item.typeName"
                                :show-overflow-tooltip="true">
                            </el-table-column>
                        </el-table-column>
                    </template>
                    <template v-else>
                        <el-table-column label="本科" prop="personNumEven"></el-table-column>
                        <el-table-column label="专科" prop="zhuanPersonNumEven"></el-table-column>
                    </template>
                    
                </el-table>
            </div>
        </template>

    </div>
</template>
  
<script>
import * as echarts from 'echarts'
import {
    getYearStrList,
    getPoorStudentYearStrList,
    getSchoolScholarshipYear
} from "@/api/poorStudent-scholarship/plan.js";
import {
    getScholarshipApplication,
    getScholarshipCollege,
    getCollegeScholarshipStatisticsList,
    poorStudentStatistics,
    benzhuanSchoolScholarshipStatistics,
    getCollegeSchoolScholarshipStatistics,
    getCollegeSchoolScholarshipStatisticsList,
    getFourOrganizationScholarshipList,
    getScholarshipStaticsByProvince,
    getSubsidyStaticsByProvince
} from "@/api/poorStudent-scholarship/statistics.js";
import exportExecl from "@/utils/exportExecl.js";

import {
    scholarshipTypeArr
} from "@/views/poorStudent-scholarship/dict.js"

export default {
    name: 'statistics',
    data() {
        return {
            yearsOptions: [],
            gjstatistics: {},
            yearStr: null,
            tableData: [],
            fourOrganizationTableData: [],
            subsidyType: [],
            subsidyStatistics: {},
            benSchoolScholarship: {
                list: [],
                personTotal: 0,
                totalMoney: 0
            },
            zhuanSchoolScholarship: {
                list: [],
                personTotal: 0,
                totalMoney: 0
            },
            zhuanUpBenSchoolScholarship: {
                list: [],
                personTotal: 0,
                totalMoney: 0
            },
            scholarshipTypeList: [],
            schoolScholarshipStudentType:'',
            scholarshipTypeArr,
            provincesTableData: []
        }
    },
    computed: {
        userType() {
            return this.$route.params && this.$route.params.type
        },
        isSubsidy() {
            return this.userType === 'subsidy'
        },
        isScholarship() {
            return this.scholarshipTypeArr.some((item) => {
                return item.code == this.userType 
            })
        },
        scholarshipType() {
            const scholarshipTypeItem = this.scholarshipTypeArr.find((item) => {
                return item.code == this.userType 
            })
            if (scholarshipTypeItem) {
                return scholarshipTypeItem.typeId
            } else {
                return 0
            }
        },
        isSchoolScholarship(){
            return this.userType === 'schoolScholarship'
        },
        schoolStatistics(){
            return this.userType === 'schoolStatistics' 
        },
    },
    created() {
        this.getYear()
    },
    mounted() {
    },
    methods: {
        studentTypeChange(e) {
            console.log(e, 'e')
        },
        handleAllExport() {
            this.download(
                "finances/schoolScholarshipStatisticsController/downLoadCollegeScholarshipStatistics",
                {
                    yearStr: this.yearStr
                },
                `校内奖学金发放汇总表单_${new Date().getTime()}.xls`
            );  
        },
        /** 导出按钮操作 */
        handleExport(type) {
            let _studentType = '';
            let REPORTID = ''
            if (type == 'ben') {
                _studentType = '本科'
                REPORTID ='schoolScholarshipStatisticsTableBen';
            } else if (type == 'zhuan') {
                _studentType = '专科'
                REPORTID ='schoolScholarshipStatisticsTableZhuan';
            } else if (type == 'four') {
                _studentType = '四大组织'
                REPORTID ='schoolScholarshipStatisticsTableFour';
            }
            let FILENAME =`校内奖学金分配明细${_studentType ? '（'+_studentType+'）' : ''}.xlsx`;
            let HEADERRANGE = 'A3:M3'
            let l= this.tableData.length;
            let TABLERANGE =`A4:M${3 + l}`;
            let REDRANGE =`A${5 + l}:M${7 + l}`
            this.$nextTick(() => {
                exportExecl(REPORTID, FILENAME, HEADERRANGE, TABLERANGE,REDRANGE)
            })
        },
        totalFun(a, b) {
            if (a && b) {
                const _total = Number(a) + Number(b)
                if (isNaN(_total)) {
                    return ''
                } else {
                    return _total
                }
            } else {
                return ''
            }
        },
        yearStrChange() {
            if (this.isScholarship) {
                this.scholarshipApplication(this.yearStr)
                this.scholarshipCollege(this.yearStr)
                // this.collegeScholarshipStatisticsList(this.yearStr)
                // 根据省份获取统计情况
                this.getprovincestatistics(this.yearStr, this.scholarshipType)
            }
            if (this.isSubsidy) {
                this.getPoorStudentStatistics(this.yearStr)
            }
            if (this.isSchoolScholarship) {
                this.getSchoolScholarshipStatistics(this.yearStr)
                this.collegeSchoolScholarshipStatistics(this.yearStr)
            }
            if (this.schoolStatistics) {
                this.getSchoolScholarshipStatistics(this.yearStr)
                this.collegeSchoolScholarshipStatistics(this.yearStr)
            }
        },
        getSchoolScholarshipStatistics(yearStr){
            this.benSchoolScholarship = {
                list: [],
                personTotal: 0,
                totalMoney: 0
            }
            this.zhuanSchoolScholarship = {
                list: [],
                personTotal: 0,
                totalMoney: 0
            }
            benzhuanSchoolScholarshipStatistics({ yearStr }).then((res) => {
                let _benPersonTotal = 0
                let _benTotalMoneyl = 0
                let _zhuanPersonTotal = 0
                let _zhuanTotalMoneyl = 0
                // let _zhuanUpBenPersonTotal = 0
                // let _zhuanUpBenTotalMoneyl = 0

                res.benStatisList && res.benStatisList.forEach((item) => {
                    _benPersonTotal = _benPersonTotal + Number(item.personNum)
                    _benTotalMoneyl = _benTotalMoneyl + Number(item.totalMoney)
                })
                res.zhuanStatisList && res.zhuanStatisList.forEach((item) => {
                    _zhuanPersonTotal = _zhuanPersonTotal + Number(item.personNum)
                    _zhuanTotalMoneyl = _zhuanTotalMoneyl + Number(item.totalMoney)
                })
                // res.zhuanShengBenStatisList && res.zhuanShengBenStatisList.forEach((item) => {
                //     _zhuanUpBenPersonTotal = _zhuanUpBenPersonTotal + Number(item.personNum)
                //     _zhuanUpBenTotalMoneyl = _zhuanUpBenTotalMoneyl + Number(item.totalMoney)
                // })

                this.benSchoolScholarship = {
                    list: res.benStatisList,
                    personTotal: _benPersonTotal,
                    totalMoney: _benTotalMoneyl
                }

                this.zhuanSchoolScholarship = {
                    list: res.zhuanStatisList,
                    personTotal: _zhuanPersonTotal,
                    totalMoney: _zhuanTotalMoneyl
                }

                // this.zhuanUpBenSchoolScholarship = {
                //     list: res.zhuanShengBenStatisList,
                //     personTotal: _zhuanUpBenPersonTotal,
                //     totalMoney: _zhuanUpBenTotalMoneyl
                // }

                this.$nextTick(() => {
                    this.initChartPie({
                        id: 'schoolScholarshipStatistics',
                        data: res.allStatisList.map((item) => {
                            return {
                                value: item.personNum,
                                name: item.typeName
                            }
                        }),
                        radius: '50%',
                        total: false
                    })
                })
            })
        },
        collegeSchoolScholarshipStatistics(yearStr){
            this.scholarshipTypeList = []
            getCollegeSchoolScholarshipStatistics({ yearStr, orgFlag:0}).then((res) => {
                let _series = [{
                    name: "本科",
                    type: 'bar',
                    stack: 'total',
                    label: {
                        show: true
                    },
                    data: []
                },{
                    name: "专科",
                    type: 'bar',
                    stack: 'total',
                    label: {
                        show: true
                    },
                    data: []
                }]
                let _college = []

                res.forEach((item) => {
                    _series[0].data.push(Number(item.benPersonTotal))
                    _series[1].data.push(Number(item.zhuanPersonTotal))
                    _college.push(item.collegeName)
                })


                this.multilayerChartBar({
                    id: 'statisticsYx',
                    xData: _college,
                    yData: _series
                })
                
            })

            getCollegeSchoolScholarshipStatisticsList({yearStr, orgFlag:0}).then((res) => {
                this.scholarshipTypeList = res && res[0] && res[0].benPersonInfoList
                this.tableData = res && res.map((item) => {
                    item.benPersonInfoList && item.benPersonInfoList.forEach((type, index) => {
                        item[type.schoolTypeId + 'ben'] = type.benPersonNum
                    })
                    item.zhuanPersonInfoList && item.zhuanPersonInfoList.forEach((type, index) => {
                        item[type.schoolTypeId + 'zhuan'] = type.zhuanPersonNum
                    })
                    item.totalPersonNum = Number(item.benTotalPersonNum) + Number(item.zhuanTotalPersonNum)
                    item.tatalMoney = Number(item.benTotalMoney) + Number(item.zhuanTotalMoney)
                    return item
                })
            })

            // 四大组织表格
            getFourOrganizationScholarshipList({yearStr, orgFlag:1}).then((res) => {
                console.log(res, 'getFourOrganizationScholarshipList')
                this.fourOrganizationTableData = res
            })
        },
        getPoorStudentStatistics(yearStr) {
            this.tableData = []
            this.subsidyStatistics = {}
            this.subsidyType = []
            poorStudentStatistics({ yearStr }).then((res) => {
                this.subsidyStatistics = res
                this.subsidyType = res.statisNumBenList || []
                this.getprovincestatistics(yearStr)
                this.$nextTick(() => {
                    this.initChartPie({
                        id: 'statisticsXzLeft',
                        data: res.statisNumBenList && res.statisNumBenList.map((item) => {
                            return {
                                value: item.stuNum,
                                name: item.typeName
                            }
                        }),
                        total: res.statisNumBenList && res.statisNumBenList.reduce((_num, item) => {
                            _num = _num + item.stuNum
                            return _num
                        }, 0)
                    })
                    this.initChartPie({
                        id: 'statisticsXzRight',
                        data: res.totalStatisZhuanList && res.totalStatisZhuanList.map((item) => {
                            return {
                                value: item.stuNum,
                                name: item.typeName
                            }
                        }),
                        total: res.totalStatisZhuanList && res.totalStatisZhuanList.reduce((_num, item) => {
                            _num = _num + item.stuNum
                            return _num
                        }, 0)
                    })
                    this.initChartBar({
                        id: 'statisticsYx',
                        source: [
                            ['product', '本科', '专科'],
                            ...res.collageStatisList && res.collageStatisList.map((item) => {
                                return [item.collageName, item.本科 || 0, item.专科 || 0]
                            })
                        ]
                    })
                    const diffCollTypeStatisObj = res.diffCollTypeStatisList.reduce((_obj, item) => {
                        _obj[item.collageName + item.educationType] = item
                        return _obj
                    }, {})

                    const _collTable = res.collageStatisList.map(element => {
                        if (element.专科 > 0) {
                            const _zhuan = diffCollTypeStatisObj[element.collageName + '专科']
                            if (_zhuan && _zhuan.diffTypeList){
                                _zhuan.diffTypeList.forEach(zhuanitem => {
                                    element[zhuanitem.diffName + '专科'] = zhuanitem.personNum || 0
                                });
                            }
                        } else {
                            res.statisNumBenList.forEach(zhuanitem => {
                                element[zhuanitem.typeName + '专科'] = 0
                            });
                        }
                        if (element.本科 > 0){
                            const _ben = diffCollTypeStatisObj[element.collageName + '本科']
                            if (_ben && _ben.diffTypeList){
                                _ben.diffTypeList.forEach(benitem => {
                                    element[benitem.diffName + '本科'] = benitem.personNum || 0
                                });
                            }
                        } else {
                            res.statisNumBenList.forEach(benitem => {
                                element[benitem.typeName + '本科'] = 0
                            });
                        }
                        return element
                    });
                    this.tableData = _collTable.reduce((arr, item, index) => {
                        if (index % 2 === 0) {
                            let rowdata = { ...item }
                            const nextRowdata = _collTable[index + 1]
                            if (nextRowdata) {
                                for (const key in nextRowdata) {
                                    rowdata[key + 'even'] = nextRowdata[key]
                                }
                            }
                            arr.push(rowdata)
                        }
                        return arr
                    }, [])
                    console.log(this.tableData , '_collTable')
                })
            })
        },
        getYear() {
            if (this.isScholarship) {
                getYearStrList({scholarshipType: this.scholarshipType}).then((res) => {
                    this.yearsOptions = res && res.map((item) => {
                        return {
                            label: item,
                            value: item
                        }
                    })
                    this.yearStr = res && res[0]
                    this.yearStrChange()
                })
            }
            if (this.isSubsidy) {
                getPoorStudentYearStrList().then((res) => {
                    this.yearsOptions = res && res.map((item) => {
                        return {
                            label: item,
                            value: item
                        }
                    })
                    this.yearStr = res && res[0]
                    this.yearStrChange()
                })
            }
            if (this.isSchoolScholarship) {
                getSchoolScholarshipYear().then((res) => {
                    this.yearsOptions = res && res.map((item) => {
                        return {
                            label: item,
                            value: item
                        }
                    })
                    this.yearStr = res && res[0]
                    this.yearStrChange()
                })
            }
            if (this.schoolStatistics) {
                getSchoolScholarshipYear().then((res) => {
                    this.yearsOptions = res && res.map((item) => {
                        return {
                            label: item,
                            value: item
                        }
                    })
                    this.yearStr = res && res[0]
                    this.yearStrChange()
                })
            }
        },
        scholarshipApplication(yearStr) {
            if (this.isScholarship) {
                getScholarshipApplication({ yearStr,  scholarshipType:this.scholarshipType}).then((res) => {
                    this.gjstatistics = res
                    this.$nextTick(() => {
                        this.initChartPie({
                            id: 'statisticsXzLeft',
                            data: [
                                { value: res.benEduTotalPersonNum, name: '本科总人数' },
                                { value: res.zhuanEduTotalPersonNum, name: '专科总人数' }
                            ],
                            total: res.benPersonTotal
                        })
                        this.initChartPie({
                            id: 'statisticsXzRight',
                            data: [
                                { value: res.benEduTotalMoney, name: '本科总金额' },
                                { value: res.zhuanEduTotalMoney, name: '专科总金额' }
                            ],
                            total: res.zhuanPersonTotal
                        })
                    })
                })
            }
        },

        // 根据省份获取获奖情况
        getprovincestatistics(yearStr, type) {
            if (this.isScholarship) {
                getScholarshipStaticsByProvince({
                    yearStr,
                    scholarshipType: type
                }).then((res) => {
                    if (res && Array.isArray(res)) {
                        let chartData = {
                            xData: [],
                            yData: [{
                                data: [],
                                type: 'bar',
                                name: '本科'
                            },{
                                data: [],
                                type: 'bar',
                                name: '专科'
                            },]
                        }
                        res.forEach((item) => {
                            chartData.xData.push(item.provinceName)
                            chartData.yData[0].data.push(item.personNum)
                            chartData.yData[1].data.push(item.zhuanPersonNum)
                        })
                        this.multilayerChartBar({
                            id: 'provincestatistics',
                            xData: chartData.xData,
                            yData: chartData.yData
                        })
                        this.provincesTableData = res.reduce((arr, item, index) => {
                            if (index % 2 === 0) {
                                let rowdata = { ...item }
                                const nextRowdata = res[index + 1]
                                if (nextRowdata) {
                                    for (const key in nextRowdata) {
                                        rowdata[key + 'Even'] = nextRowdata[key]
                                    }
                                }
                                arr.push(rowdata)
                            }
                            return arr
                        }, [])
                    }
                })
            }

            if (this.isSubsidy) {
                getSubsidyStaticsByProvince({
                    yearStr
                }).then((res) => {
                    let concatProvince = res.reduce((obj, item)=> {
                        if (item.provinceName in obj) {
                            obj[item.provinceName][`${item.educationType}-${item.diffName}`] = item.personNum
                        } else {
                            item[`${item.educationType}-${item.diffName}`] = item.personNum
                            obj[item.provinceName] = item
                        }
                        return obj
                    },{})
                    let chartData = {
                        xData: Object.keys(concatProvince) || [],
                        yData: []
                    }
                    console.log(concatProvince, 'concatProvince')
                    this.subsidyType.forEach((item) => {
                        let benData = []
                        let zhuanData = []
                        chartData.xData.forEach((province) => {
                            benData.push(concatProvince[province][`本科-${item.typeName}`] || 0)
                            zhuanData.push(concatProvince[province][`专科-${item.typeName}`] || 0)
                        })
                        chartData.yData.push({
                            data: benData,
                            type: 'bar',
                            name: `本科-${item.typeName}`,
                            stack: 'ben'
                        })
                        chartData.yData.push({
                            data: zhuanData,
                            type: 'bar',
                            name: `专科-${item.typeName}`,
                            stack: 'zhuan'
                        })
                    })
                    this.multilayerChartBar({
                        id: 'provincestatistics',
                        xData: chartData.xData,
                        yData: chartData.yData
                    })
                    const tableData = Object.values(concatProvince)
                    this.provincesTableData = tableData.reduce((arr, item, index) => {
                        if (index % 2 === 0) {
                            let rowdata = { ...item }
                            const nextRowdata = res[index + 1]
                            if (nextRowdata) {
                                for (const key in nextRowdata) {
                                    rowdata[key + 'Even'] = nextRowdata[key]
                                }
                            }
                            arr.push(rowdata)
                        }
                        return arr
                    }, [])
                })
            }
        },

        scholarshipCollege(yearStr) {
            if (this.isScholarship) {
                getScholarshipCollege({ yearStr, scholarshipType:this.scholarshipType }).then((res) => {
                    this.$nextTick(() => {
                        const xyStatistics = res && res.map((item) => {
                            return [item.collageName, item.eduTotalMoney, item.zhuanTotalMoney]
                        })
                        this.initChartBar({
                            id: 'statisticsYx',
                            source: [
                                ['product', '本科', '专科'],
                                ...xyStatistics
                            ]
                        })
                        this.tableData = res.reduce((arr, item, index) => {
                            if (index % 2 === 0) {
                                let rowdata = { ...item }
                                const nextRowdata = res[index + 1]
                                if (nextRowdata) {
                                    for (const key in nextRowdata) {
                                        rowdata[key + 'even'] = nextRowdata[key]
                                    }
                                }
                                arr.push(rowdata)
                            }
                            return arr
                        }, [])
                    })
                })
            }
        },
        // collegeScholarshipStatisticsList(yearStr) {
        //     if (this.isScholarship) {
        //         this.tableData = []
        //         getCollegeScholarshipStatisticsList({ yearStr }).then((res) => {
        //             this.tableData = res.reduce((arr, item, index) => {
        //                 if (index % 2 === 0) {
        //                     let rowdata = { ...item }
        //                     const nextRowdata = res[index + 1]
        //                     if (nextRowdata) {
        //                         for (const key in nextRowdata) {
        //                             rowdata[key + 'even'] = nextRowdata[key]
        //                         }
        //                     }
        //                     arr.push(rowdata)
        //                 }
        //                 return arr
        //             }, [])
        //         })
              
        //     }
        // },
        initChartPie(props) {
            const option = {
                title: {
                    zlevel: 0,
                    show: Boolean(props.total),
                    text: [
                        '{value|总计：' + props.total + '人}',
                    ].join('\n'),
                    top: 'center',
                    left: '50%',
                    textAlign: 'center',
                    textStyle: {
                        rich: {
                            value: {
                                color: '#303133',
                                fontSize: 12,
                                lineHeight: 20
                            }
                        }
                    }
                },
                series: [{
                    type: 'pie',
                    radius: props.radius? props.radius: ['50%', '70%'],
                    label: {
                        normal: {
                            show: true,
                            formatter: '{b}\n{c}'
                        }
                    },
                    data: props.data
                }]
            }
            this.chart = echarts.init(document.getElementById(props.id))
            this.chart.setOption(option)
        },
        initChartBar(props) {
            const option = {
                legend: {},
                tooltip: {},
                dataset: {
                    source: props.source
                },
                grid: {
                    top: '12%',
                    left: '2%',
                    right: '2%',
                    bottom: '15%',
                    containLabel: true
                },
                xAxis: { type: 'category' },
                yAxis: {},
                series: [{ type: 'bar' }, { type: 'bar' }]
            }
            this.chart = echarts.init(document.getElementById(props.id))
            this.chart.setOption(option)
        },
        multilayerChartBar(props) {
            const option = {
                legend: {},
                tooltip: {},
                dataset: {
                    source: props.source
                },
                grid: {
                    top: '12%',
                    left: '2%',
                    right: '2%',
                    bottom: '15%',
                    containLabel: true
                },
                xAxis: { 
                    type: 'category',
                    data: props.xData
                },
                yAxis: {
                    type: 'value'
                },
                series: props.yData
            }
            this.chart = echarts.init(document.getElementById(props.id))
            this.chart.setOption(option)
        }
    }

}
</script>
  
<style lang="scss" scoped>
.statisticsPie {
    height: 240px;

    &-item {
        height: 100%;
        background-color: #f8f8f9;

        &-title {
            height: 40px;
            line-height: 40px;
            text-align: center;
            font-size: 14px;
            font-weight: 600;
        }

        &-content {
            height: calc(100% - 40px);
            display: flex;

            .content {
                &-echarts {
                    flex: 1;
                }

                &-detail {
                    width: 200px;
                    padding-top: 16px;

                    &-item {
                        height: 40px;
                        line-height: 40px;
                    }
                }
            }
        }
    }
}

.statisticsBar {
    width: 100%;
    height: 280px;
    margin-top: 20px;

    &-title {
        height: 20px;
        line-height: 20px;
    }

    &-content {
        height: calc(100% - 20px);
    }
}
.schoolScholarship-list{
    width: 100%;
    height: 100%;
    background-color: rgb(239, 239, 239);
    padding: 10px;
    &-header{
        font-weight: 600;
        .header-title{
            text-align: center;
            height: 22px;
            line-height: 22px;
        }
        .header-item{
            display: flex;
            justify-content: space-between;
            height: 22px;
            line-height: 22px;
        }
    }
    &-container{
        width: 100%;
        height: calc(100% - 44px);
        overflow-y: auto;
        .container-item{
            display: flex;
            justify-content: space-between;
            height: 20px;
            line-height: 20px;
        }
    }
}
.statisticsTable{
    &-SchoolScholarshipQuery{
        display: flex;
        margin-bottom: 8px;
        &-item{
            margin-right: 10px;
            line-height: 28px;
        }
    }
}
.provincestatisticsTable{
    width: 100%;
    &-chart{
        height: 260px;
    }
}
</style>